// 项目配置项
function getData(key) {
  let list = [
    {
      id: 1,
      cname: "Ai修图",
      type: 1,
      ename: "aibeauty-web",
      gitUrl: "https://code.yw20.cn/questai/h5/aibeauty-web.git",
      lanhu: "",
      apiUrl:
        "https://apifox.com/apidoc/shared/d7612531-4a1d-40a6-850a-07d0a0639344/api-301836922",
      prototype:
        "https://modao.cc/proto/vB9QoQwosvdc4gtqboeAST/sharing?view_mode=device&screen=rbpUlj8r3o2xm6O8A&canvasId=rcUljiZ1Bx2aed1O",
      pass: "E6ZG73kI",
      actNum: "qzadmin",
      release:
        "https://jenkins-leshu.yw20.cn/job/QuestAI_aibeauty-web/build?delay=0sec",
    },
    {
      id: 2,
      cname: "AI写歌",
      ename: "aimusic-web",
      gitUrl: "",
      lanhu: "",
      apiUrl: "",
      prototype: "",
      pass: "@Bc58VER",
      actNum: "qzadmin",
      type: 1,
    },
    {
      id: 3,
      cname: "数字人后台",
      ename: "digitalhuman-web",
      gitUrl: "",
      lanhu: "",
      apiUrl: "",
      prototype: "",
      pass: "GMvx7r!E",
      actNum: "qzadmin",
      type: 1,
    },
    {
      id: 4,
      cname: "恋小言-后台",
      ename: "love-web",
      gitUrl: "",
      lanhu: "",
      apiUrl: "",
      prototype: "",
      pass: "lxy03",
      actNum: "qzadmin ",
      type: 1,
    },
    {
      id: 5,
      cname: "输入法Web",
      ename: "aimusic-web",
      gitUrl: "",
      lanhu: "",
      apiUrl: "",
      prototype: "",
      pass: "qscf1587 ",
      actNum: "qzadmin",
      type: 1,
    },
    {
      id: 6,
      cname: "维吾尔输入法",
      ename: "uyghurinput-web",
      gitUrl: "",
      lanhu: "",
      apiUrl: "",
      prototype: "",
      pass: "",
      actNum: "",
      type: 1,
    },
    {
      id: 7,
      cname: "章鱼隐藏项目",
      ename: "octopus-privacy-hide-manager-web",
      gitUrl: "",
      lanhu: "",
      apiUrl: "",
      prototype: "",
      pass: "3XNowgnJ ",
      actNum: "qzadmin ",
      type: 1,
      release:
        "https://jenkins-leshu.yw20.cn/job/QZ_octopus-privacy-hide-manager/build?delay=0sec",
    },
    {
      id: 8,
      cname: "财经静态页面",
      ename: "finance-web",
      gitUrl: "",
      lanhu:
        "https://lanhuapp.com/web/#/item/project/detailDetach?pid=4a3ce564-fee8-41a3-ab61-023e8c9140d5&image_id=f2e14d91-21c6-4c51-8579-cdd73b0ff133&tid=92e917c6-a87b-412d-be01-57cde960fdd0&project_id=4a3ce564-fee8-41a3-ab61-023e8c9140d5&fromEditor=true&type=image",
      apiUrl:
        "http://121.5.26.214:9062/doc.html#/api/%E7%88%86%E4%BB%93%E7%AE%A1%E7%90%86/getCryptoExchangeLiquidationMapUsingGET",
      prototype: "",
      pass: "",
      actNum: "",
      type: 2,
    },
    {
      id: 9,
      cname: "乐薯智投广告投放",
      type: 1,
      ename: "advert_manager",
      gitUrl: "",
      lanhu: "",
      apiUrl:
        "http://10.10.20.61:8082/doc.html#/admin%E5%90%8E%E5%8F%B0api%E6%8E%A5%E5%8F%A3/%E5%8D%8E%E4%B8%BA%E9%B2%B8%E9%B8%BF%E8%B4%A6%E5%8F%B7%E7%AE%A1%E7%90%86/getAdvertisersUsingPOST",
      prototype: "",
      pass: "111111",
      actNum: "13916339747",
    },
    {
      id: 10,
      cname: "收支系统",
      type: 1,
      ename: "balance",
      gitUrl: "",
      lanhu: "",
      apiUrl: "",
      prototype: "",
      pass: "111111",
      actNum: "13916339747",
    },
    {
      id: 11,
      cname: "石器，微信小游戏，h5",
      type: 1,
      ename: "stone-wx-manager",
      gitUrl: "",
      lanhu: "",
      apiUrl:
        "http://124.220.84.240:8186/api/doc.html#/stone-gm%20%20%E6%95%B0%E6%8D%AE%E4%B8%AD%E5%BF%83%20api%20%E6%8E%A5%E5%8F%A3/GM%EF%BC%9A%E6%95%B0%E6%8D%AE%E6%B1%87%E6%80%BB/baseActiveUsingGET",
      prototype: "",
      pass: "SuperManager123",
      actNum: "manager",
    },
    {
      id: 12,
      cname: "圣经项目",
      type: 2,
      ename: "mind-page",
      gitUrl: "",
      lanhu:
        "https://lanhuapp.com/web/#/item/project/detailDetach?pid=8f5a10f2-bdd6-4898-be00-77bc6332bb98&image_id=0201c335-7799-4822-a910-10a1c1e0de3d&tid=92e917c6-a87b-412d-be01-57cde960fdd0&project_id=8f5a10f2-bdd6-4898-be00-77bc6332bb98&fromEditor=true&type=image",
      apiUrl: "",
      prototype: "",
      pass: "",
      actNum: "",
    },
    {
      id: 13,
      cname: "圣经项目",
      type: 1,
      ename: "godslove-web",
      gitUrl: "",
      lanhu: "",
      apiUrl: "",
      prototype: "",
      pass: "SuperManager123",
      actNum: "manager",
    },
    {
      id: 14,
      cname: "财经项目",
      type: 1,
      ename: "finance-manager",
      gitUrl: "",
      lanhu: "",
      apiUrl: "http://10.10.20.46:9061/doc.html#/home",
      prototype: "",
      pass: "pmaO#q8cN0CpXQ%1",
      actNum: "manager",
    },
    {
      id: 15,
      cname: "美颜后台",
      type: 1,
      ename: "beauty-manager",
      gitUrl: "",
      lanhu: "",
      apiUrl: "",
      prototype: "",
      pass: "43QfYv99",
      actNum: "manager",
      release:
        "https://jenkins-leshu.yw20.cn/job/QZ_beauty-manager/build?delay=0sec",
    },
    {
      id: 16,
      cname: "星秀美颜",
      type: 1,
      ename: "kitBeauty-web",
      gitUrl: "",
      lanhu: "",
      apiUrl: "",
      prototype: "",
      pass: "lxy03",
      actNum: "qzadmin",
    },
    {
      id: 17,
      cname: "漫画",
      type: 1,
      ename: "comic-web",
      gitUrl: "",
      lanhu: "https://qjp9oye1d3.feishu.cn/wiki/KzW9wCm3OimyBvkXwxCcaR9EnQf",
      apiUrl:
        "https://apifox.com/apidoc/shared/0a4f6c96-46d5-4190-b994-2b31f251bc6a",
      prototype:
        "https://modao.cc/proto/vB9QoQwosvdc4gtqboeAST/sharing?view_mode=device&screen=rbpUnyqOs3pxij7X1&canvasId=rcUnyr2ZvCkgrq3K",
      pass: "E6ZG73kI",
      actNum: "qzadmin",
    },
    {
      id: 18,
      cname: "支付页模版",
      type: 1,
      ename: "vue-template-h5",
      gitUrl: "",
      lanhu:
        "https://lanhuapp.com/web/#/item/project/detailDetach?pid=8bf3003e-d6b3-424d-82b5-1ca6474153e8&image_id=85e3693a-b206-4001-853b-3cae8aa1af65&tid=92e917c6-a87b-412d-be01-57cde960fdd0&project_id=8bf3003e-d6b3-424d-82b5-1ca6474153e8&fromEditor=true&type=image",
      apiUrl: "http://10.10.20.20:5000/api/login/getTokens",
      prototype: "",
      pass: "",
      actNum: "",
    },
  ];
  let dataStr = localStorage.getItem(key);
  if (dataStr) {
    return JSON.parse(dataStr);
  } else {
    return list;
  }
}
function setData(key, data, type) {
  let arr = getData("projectList");
  switch (type) {
    case "add":
      arr.push({ ...data, id: arr.length + 1 });
      break;
    case "delete":
      arr = getData("projectList").filter((item) => item.id != data.id);
      break;
    default:
      arr = arr.map((item) => {
        if (item.id == data.id) {
          return data;
        }
        return item;
      });
      break;
  }
  console.log(data, arr, "列表");

  localStorage.setItem(key, JSON.stringify(arr));
}
function convertTo2DArray(arr, size) {
  // 检查输入是否有效
  if (!Array.isArray(arr) || typeof size !== "number" || size <= 0) {
    throw new Error("无效的输入：请提供有效的数组和正整数大小");
  }

  const result = [];
  // 遍历原数组，按指定大小分割
  for (let i = 0; i < arr.length; i += size) {
    // 从当前索引开始，截取size个元素
    const chunk = arr.slice(i, i + size);
    result.push(chunk);
  }

  return result;
}
export function projectList(data = {}) {
  return new Promise((resolve, reject) => {
    let filterData = getData("projectList");
    let total = getData("projectList").length;
    if (data.type) {
      filterData = getData("projectList").filter(
        (item) => item.type == data.type
      );
      total = filterData.length;
    }
    if (data.cname) {
      filterData = getData("projectList").filter((item) =>
        item.cname.includes(data.cname)
      );
      total = filterData.length;
    }
    if (data.ename) {
      filterData = getData("projectList").filter((item) =>
        item.ename.includes(data.ename)
      );
      total = filterData.length;
    }
    if (data.page && data.limit) {
      filterData = convertTo2DArray(filterData, data.limit)[data.page - 1];
    }

    resolve({ data: filterData, total });
  });
}
export function projectAdd(data) {
  return new Promise((resolve, reject) => {
    setData("projectList", data, "add");
    resolve({ msg: "保存成功" });
  });
}
export function projectEdit(data) {
  return new Promise((resolve, reject) => {
    if (!data.id) {
      reject({ msg: "ID不能为空" });
    }
    setData("projectList", data, "edit");
    resolve({ msg: "编辑成功" });
  });
}
export function projectDelete(data) {
  return new Promise((resolve, reject) => {
    if (!data.id) {
      reject({ msg: "ID不能为空" });
    }
    setData("projectList", data, "delete");
    resolve({ msg: "删除成功" });
  });
}
